package org.ucas.faker.web.utils.tech;

import java.util.ArrayList;
import java.util.List;

public class SentenceWithProperty {
	String sentence;
	ArrayList<Integer> pos;
	ArrayList<String> prop;
	
	void getBeforeAfter(int start,int end, List<String> keyCixing, List<String> before, List<Integer> bpos,List<String> after, List<Integer> apos){

		before.clear();
		bpos.clear();
		after.clear();
		apos.clear();
		
		int t=0;
		while(t<pos.size()&&pos.get(t)<start) t++;
		while(t<pos.size()&&pos.get(t)<end) {keyCixing.add(prop.get(t));t++;}
		
		int i=0;
		while(i<pos.size()&&pos.get(i)<start) i++;
	
		before.addAll(prop.subList(0, i));
		bpos.addAll(pos.subList(0, i));
		
		while(i<pos.size()&&pos.get(i)<end) i++;
		after.addAll(prop.subList(i>pos.size()?pos.size():i, pos.size()));
		apos.addAll(pos.subList(i>pos.size()?pos.size():i, pos.size()));
		

		//for(String bs : before) System.out.print(bs+" ");
		//System.out.print("---");
		//for(String af : after) System.out.print(af+" ");
		//System.out.println();
	}
	SentenceWithProperty(String sent, String sentProp){
		//System.out.println("\n\n***** Notice ******\n");
		//System.out.println(sent+"  "+sentProp);

		sentence = sent;
		pos  = new ArrayList<>();
		prop = new ArrayList<>();
		String [] fenci = sentProp.split("\\|");
        //System.out.println("Fenci: ");
        int startpos = 0;
        for(String s : fenci){
        	String [] tuple2 = s.split("/");
//        	if(tuple2.length<2) continue;
        	pos.add(startpos);
        	prop.add(tuple2[1]);//add property
        	//System.out.print(tuple2[0]+"("+startpos+","+tuple2[0].length()+") ");
        	startpos += tuple2[0].length();
        	
//        	for(String ss:s.split("/"))
//        		System.out.print(ss+" "+startpos);
//        	System.out.print("\t");
        }
        
//        for(int i=0;i<pos.size();i++){
//        	System.out.print(pos.get(i)+":"+prop.get(i)+"\t");
//        }
        //System.out.println();           

		//System.out.println("\n***** End ******\n\n");
	}
}